import Vue from "vue";
import VueRouter from "vue-router";

// 路由懒加载
const Home = () => import("../views/home/home.vue");
const Category = () => import("../views/category/category.vue");
const Shopcart = () => import("../views/shopcart/shopcart.vue");
const Profile = () => import("../views/profile/profile.vue");
// 注入插件
Vue.use(VueRouter);
// 定义路由
const routes = [
  {
    path: "",
    redirect: "/home",
  },
  {
    path: "/home",
    component: Home,
  },
  {
    path: "/category",
    component: Category,
  },
  {
    path: "/shopcart",
    component: Shopcart,
  },
  {
    path: "/profile",
    component: Profile,
  },
];
// 创建router实例
const router = new VueRouter({
  routes,
  // 模式转为history，url中去掉#
  mode: "history",
});

// 导出实例
export default router;
